package com.gxust.mapper;

import com.gxust.pojo.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ProductMapper {
    @Select("select * from product where product.SellerID = #{id}")
    List<Product> list(Integer id);
    //    @Select("select productId,productName,productDescription,productPrice,productImageURL,productStock,creationDate,updateDate,categoryName,sellerId " +
//            "from product,category where product.CategoryID=category.CategoryID")
//    List<Product> list();

    @Insert("insert into Product (productName,productDescription,productPrice,productStock,categoryId,sellerId) " +
            "values (#{productName}, #{productDescription}, #{productPrice},#{productStock},#{categoryId},#{sellerId})")
    void insert(Product product);

    @Delete("delete from product where ProductID = #{productId}")
    void del(Product product);

    @Update("update product set ProductName = #{productName} , ProductDescription = #{productDescription} " +
            ",ProductImageURL = #{productImageUrl} ,ProductPrice = #{productPrice} ,ProductStock = #{productStock}, " +
            "CategoryID = #{categoryId},UpdateDate =  CURRENT_TIMESTAMP " +
            "where ProductID = #{productId}")
    void update(Product product);

    @Select("select * from product where ProductID = #{id}")
    Product productbyid(Integer id);

//    商城首页的[热门商品]商品列表
    @Select("SELECT * FROM product ORDER BY RAND() LIMIT 15")
    List<Product> mallListHot();

    //    商城首页的[热门商品]商品列表
    @Select("SELECT * FROM product where SellerID = 1 ORDER BY RAND() LIMIT 15")
    List<Product> mallListSelect();

    @Select("SELECT * FROM product")
    List<Product> mallList();

    @Select("select * from product where SellerID = #{id}")
    List<Product> ProductBySellerId(Integer id);
}
